package com.ztgf.pay.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.pay.models.bo.PayUserBO;
import com.ztgf.pay.models.dto.PayUserDTO;
import com.ztgf.pay.models.service.IPayUserService;
import com.ztgf.pay.models.service.IReceiveNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/**
 * 用户信息表控制器
 *
 * @author mxli
 * @Date 2020-07-30 12:13:56
 */

@RestController
@RequestMapping("/api/payNotify")
@Slf4j
@Api(value = "PayNotifyController",tags = "支付回调Api接口")
public class PayNotifyController {

    @DubboReference
    private IReceiveNoticeService receiveNoticeService;

    @PostMapping("/zj")
    @ApiOperation(value = "中金异步回调",notes = "中金异步回调")
    public void doZjNotice(HttpServletRequest request, HttpServletResponse response){
//        receiveNoticeService.doNotice(request, response);


        //添加日志
        String result = "";
        try {
            request.setCharacterEncoding("UTF-8");
            request.setCharacterEncoding("UTF-8");

            // 1 获得参数ptncode, trdcode, message和signature
            String ptncode = request.getParameter("ptncode");
            String trdcode = request.getParameter("trdcode");
            String message = request.getParameter("message");
            String signature = request.getParameter("signature");
            result = receiveNoticeService.doZjNotice(ptncode, trdcode, message, signature);
        } catch (Exception e) {
            // 4 处理响应报文参数
            e.printStackTrace();
        } finally {
            // 5 响应智融平台
            PrintWriter out = null;
            try {
                out = response.getWriter();
                out.print(result);
                out.flush();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (null != out) {
                    out.close();
                }
            }
        }

    }

}
